home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH05 / PGM5_5.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-09  |  1.8 KB  |  90 lines

  1. ; Sample Structure Definitions and Accesses.
  2. ;
  3. ; Randall Hyde
  4.  
  5.  
  6. dseg        segment    para public 'data'
  7.  
  8.  
  9. ; The following structure holds the bit values for an 80x86 mod-reg-r/m byte.
  10.  
  11. mode        struct
  12. modbits        byte    ?
  13. reg        byte    ?
  14. rm        byte    ?
  15. mode        ends
  16.  
  17.  
  18. Instr1Adrs    mode    {}    ;All fields uninitialized.
  19. Instr2Adrs    mode    {}
  20.  
  21.  
  22. ; Some structures with initialized fields.
  23.  
  24. axbx        mode    {11b, 000b, 000b}    ;"ax, ax" adrs mode.
  25. axdisp        mode    {00b, 000b, 110b}    ;"ax, disp" adrs mode.
  26. cxdispbxsi    mode    {01b, 001b, 000b}    ;"cx, disp8[bx][si]" mode.
  27.  
  28.  
  29. ; Near pointers to some structures:
  30.  
  31. sPtr1        word    axdisp
  32. sPtr2        word    Instr2Adrs
  33.  
  34. dseg        ends
  35.  
  36.  
  37. cseg        segment    para public 'code'
  38.         assume    cs:cseg, ds:dseg
  39.  
  40. Main        proc
  41.         mov    ax, dseg    ;These statements are provided by
  42.         mov    ds, ax        ; shell.asm to initialize the
  43.         mov    es, ax        ; segment register.
  44.  
  45.  
  46. ; To access fields of a structure variable directly, just use the "."
  47. ; operator like you would in Pascal or C:
  48.  
  49.         mov    al, axbx.modbits
  50.         mov    Instr1Adrs.modbits, al
  51.  
  52.         mov    al, axbx.reg
  53.         mov    Instr1Adrs.reg, al
  54.  
  55.         mov    al, axbx.rm
  56.         mov    Instr1Adrs.rm, al
  57.  
  58.  
  59. ; When accessing elements of a structure indirectly (that is, using a
  60. ; pointer) you must specify the structure type name as the first
  61. ; "field" so MASM doesn't get confused:
  62.  
  63.         mov    si, sPtr1
  64.         mov    di, sPtr2
  65.  
  66.         mov    al, ds:[si].mode.modbits
  67.         mov    ds:[di].mode.modbits, al
  68.  
  69.         mov    al, ds:[si].mode.reg
  70.         mov    ds:[di].mode.reg, al
  71.  
  72.         mov    al, ds:[si].mode.rm
  73.         mov    ds:[di].mode.rm, al
  74.  
  75.  
  76. Quit:        mov    ah, 4ch        ;Magic number for DOS
  77.         int    21h        ; to tell this program to quit.
  78. Main        endp
  79.  
  80. cseg        ends
  81.  
  82. sseg        segment    para stack 'stack'
  83. stk        byte    1024 dup ("stack   ")
  84. sseg        ends
  85.  
  86. zzzzzzseg    segment    para public 'zzzzzz'
  87. LastBytes    byte    16 dup (?)
  88. zzzzzzseg    ends
  89.         end    Main
  90.